/*                          UX-Framework                               
 *                                                                 
 *  iZE Co.,Ltd. Copyright 2009 All rights reserved.          
 *  This file is distributed under the terms of the GNU Lesser 
 *  General Public License, described in file LICENSE.                                     
 */
package jp.ize.ux;

// {{{ imports
#if flash9
import flash.display.Sprite;
import flash.events.Event;
import flash.events.FocusEvent;
#elseif flash
import flash.MovieClip;
#end

import jp.ize.ux.UXObject;
// }}}
#if flash9
// {{{ class XXSprite extends Sprite
class XXSprite extends Sprite
{
	// {{{ public var xxobj(default, default) : XXObj
	/**
	 * XXObjeへのポインタを格納.
	 */
	public var xxobj(default, default) : XXObj;
	// }}}
	// {{{ public function new()
	public function new() { super(); }
	// }}}
}
// }}}
#elseif flash
// {{{ class XXSprite extends MovieClip
class XXSprite extends MovieClip
{
	// {{{ public var xxobj(default, default) : XXObj
	/**
	 * XXObjeへのポインタを格納.
	 */
	public var xxobj(default, default) : XXObj;
	// }}}
	// {{{ public function new() { }
	public function new() { }
	// }}}
}
// }}}
#end

// {{{ class XXObj extends UXContainer
/** 
 * XXObj クラス<br>
 * 内部にSprite(flash 8 以前ではMovieClip)を保持するオブジェクトです。<br>
 * 主な子クラス: UXObject, Root<br>
 * 
 *
 * @author		iZE Co., Ltd.<br>
 * @version		$Id: Core.hx 32 2009-02-12 07:23:35Z yimai.v $<br>
 */
class XXObj extends UXContainer
{	
	// {{{ private var sprite(default, default) : XXSprite
	/**
	 * 生のスプライトと同等のインスタンスを格納する変数
	 */
	private var sprite(default, default) : XXSprite;
	// }}}
	// {{{ public function new()
	/**
	 * コンストラクタ.
	 */
	public function new()
	{
		super();
		sprite = new XXSprite();
		sprite.xxobj = this;
	}
	// }}}
	// {{{ public function addChild( child : T ) : Void
	/**
	 * 子要素を加えます。
	 */
	public override function addChild( child : UXObject ) : Void
	{
		// just sample
		super.addChild(child);
		child.parent = this;
		var child : XXObj = child;
		#if flash9
		sprite.addChild(child.sprite);
		#end
	}
	// }}}
	// {{{ public function removeChild( child : T ) : Void
	/**
	 * 指定された子要素をコンテナから削除します。
	 */
	public override function removeChild( child : UXObject ) : Void
	{
	}
	// }}}
	// just sample.
	#if flash10
	// {{{ public function setChildIndex(child: UXObject, idx: Int) {

	public function setChildIndex(child: UXObject, idx: Int) {
		var child : XXObj = child;
		sprite.setChildIndex(child.sprite, idx);
	}

	// }}}
	#end
	// {{{ public static function flashEvent2UXEvent( originalEvent : Event ) : UXEvent
	// just sample.
	public static function flashEvent2UXEvent( originalEvent : Event ) : UXEvent
	{
		// just just sample.
		var uxev = "";
		uxev = originalEvent.type;
		switch( uxev ) {
			case UXMouseEvent.CLICK:
			case UXMouseEvent.DOUBLE_CLICK:
			case UXMouseEvent.DOWN:
			case UXMouseEvent.UP:
			case UXMouseEvent.OVER:
			case UXMouseEvent.OUT:
			case UXMouseEvent.MOVE:
			case UXMouseEvent.WHEEL:
			case UXMouseEvent.ROLL_OUT:
			case UXMouseEvent.ROLL_OVER:

			case UXKeyboardEvent.KEY_DOWN:
			case UXKeyboardEvent.KEY_UP:
		}
		//public function new( type : String, local : UXPoint, global : UXPoint, mods : Array<KeyMods>, ?delta : Int )
		return new UXMouseEvent( uxev, null, null, null);
		//public function new( type : String, code : Int, mods : Array<KeyMods>, ?location : KeyLocation )
		//return new UXKeyboardEvent( uxev, null, null, null);
	}

	// }}}
	// {{{ public static function event2FlashEvent( name : String ) : String

	public static function event2FlashEvent( name : String ) : String
	{
		// just just sample.
		/*
		return switch( name ) {
			case UXMouseEvent.DOWN:
				"mouseDown";
			default:
				"mouseDown";				
		}
		*/
		return name;
	}

	// }}}
}
// }}}
